package pro.cherish.smartfile;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.reactive.config.EnableWebFlux;
import pro.cherish.smartfile.config.listener.EnvironmentPreparedListener;
import pro.cherish.smartfile.config.listener.WebServerInitializedListener;

import javax.annotation.PostConstruct;

/**
 * @author lys
 */
@EnableWebFlux
@SpringBootApplication
@EnableConfigurationProperties
@EnableTransactionManagement
@EnableScheduling
@Slf4j
public class SmartFileApplication {

    @Value("${spring.datasource.url}")
    private String dbUrl;

    @Value("${spring.redis.host}")
    private String redisHost;

    public static void main(String[] args) {
        SpringApplication app = new SpringApplicationBuilder(SmartFileApplication.class).build(args);
        //添加监听器
        app.addListeners(new EnvironmentPreparedListener(),
                new WebServerInitializedListener());
        app.run(args);
        log.info("smart file 服务启动!");
    }

    /**
     * 系统关键环境打印
     *
     * @param
     * @Return void
     * @Author lys
     * @Date 2020-5-27 23:03
     */
    @PostConstruct
    public void printEnvironment() {
        log.info("======================================项目环境=================================");
        log.info("请保证数据库连接URL={}", dbUrl);
        log.info("请保证redis连接={}", redisHost);
        log.info("======================================项目环境=================================");
    }


}
